home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / cenvid9.zip / SCREEN.LIB < prev    next >
Text File  |  1994-03-04  |  9KB  |  238 lines

  1. //**********************************************************************
  2. //*** Screen.lib - A library of useful utilities for writing to the  ***
  3. //*** ver.1        screen. For when the internal CEnvi() Screenxxx() ***
  4. //***              routines are not enough.                          ***
  5. //***
  6. //***
  7. //**** SetCursor(): Set cursor at screen Row and Column
  8. // SYNTAX: void SetCursor(int Row,int Col)
  9. //
  10. //**** GetCursor(): Get current cursor position
  11. // SYNTAX: void GetCursor(int Row,int Col)
  12. //
  13. //**** ScrWrite(): Write string or character, position, and attributes
  14. // SYNTAX: void ScrWrite(string Text or byte Char)
  15. //         void ScrWrite(string Text or byte Char,int Row,int Col)
  16. //         void ScrWrite(string Text or byte Char,int Row,int Col,int ForeColor,int BackColor)
  17. // WHERE: Text - Character string to write
  18. //        Row, Col - Cursor position; if not supplied then current position
  19. //        ForeColor, BackColor - Attributes for string, else current attributes
  20.    #define BLACK           0
  21.    #define BLUE            1
  22.    #define GREEN           2
  23.    #define CYAN            3
  24.    #define RED             4
  25.    #define MAGENTA         5
  26.    #define BROWN           6
  27.    #define LIGHTGRAY       7
  28.    #define DARKGRAY        8
  29.    #define LIGHTBLUE       9
  30.    #define LIGHTGREEN      10
  31.    #define LIGHTCYAN       11
  32.    #define LIGHTRED        12
  33.    #define LIGHTMAGENTA    13
  34.    #define YELLOW          14
  35.    #define WHITE           15
  36.    #define BLINK           0x8  // OR with background color to make blink
  37. //
  38. //**** Clear(): Clear screen
  39. // SYNTAX: void Clear()
  40. //         void Clear(ForeColor,BackColor)
  41. //
  42. //**** Scroll(): Scroll a region of the screen
  43. // SYNTAX: void Scroll(LineCount)
  44. //         void Scroll(LineCount,TopRow,LeftCol,BottomRow,RightCol)
  45. //         void Scroll(LineCount,ForeColor,BackColor)
  46. //         void Scroll(LineCount,TopRow,LeftCol,BottomRow,RightCol,ForeColor,BackColor)
  47. //
  48. //**** TextBox()
  49. // SYNTAX: void TextBox(TopRow,LeftCol,BottomRow,RightCol)
  50. //         void TextBox(TopRow,LeftCol,BottomRow,RightCol,Treatment)
  51. //         void TextBox(TopRow,LeftCol,BottomRow,RightCol,ForeColor,BackColor)
  52. //         void TextBox(TopRow,LeftCol,BottomRow,RightCol,ForeColor,BackColor,Treatment)
  53. // WHERE: Treatment is a character to use as the border (e.g. '*') or'ed with one of the following
  54.    #define DOUBLE_LINE  0x100 // Use double-line graphics characters
  55.    #define SINGLE_LINE  0x200 // use single-line graphics characters around box
  56.    #define SHADOW       0x400 // drop down a shadow from the box to desktop
  57.    #define NOFILL       0x800 // only draw border
  58. //
  59. //**** ReadCharacter()
  60. // SYNTAX: byte ReadCharacter()
  61. //         byte ReadCharacter(int Attribute)
  62. //         byte ReadCharacter(int Row,int Col)
  63. //         byte ReadCharacter(int Row,int Col,int Attribute)
  64. //
  65. //
  66. //**** SetCursorType()
  67. // SYNTAX: void SetCursorType(int Cursor)
  68. //         void SetCursrorType(int StartingLine,int EndingLine)
  69.    #define HIDE_CURSOR 0xFFFF
  70. //
  71. //**** GetCursorType()
  72. // SYNTAX: int GetCursorType()
  73. //
  74. //**** SetAttribute()
  75. // SYNTAX: void SetAttribute(int Attribute)
  76. //         void SetAttribute(int ForeColore,int BackColor)
  77. //
  78. //**** HorzLine(): Draw a horizontal line
  79. // SYNTAX: void HorzLine(Row,LeftCol,Treatment)
  80. //         void HorzLine(Row,LeftCol,Len,ForeColor,BackColor,Treatment)
  81. // WHERE: Treatment is SINGLE_LINE, DOUBLE_LINE, or character to draw with
  82. //
  83. //**** VertLine(): Draw a vertical line
  84. // SYNTAX: void VertLine(TopRow,Col,Treatment)
  85. //         void VertLine(TopRow,Col,Len,ForeColor,BackColor,Treatment)
  86. // WHERE: Treatment is SINGLE_LINE, DOUBLE_LINE, or character to draw with
  87. //
  88. //
  89. //
  90.  
  91. slForeColor = LIGHTGRAY;
  92. slBackColor = BLACK;
  93.  
  94.  
  95. SetCursor(pRow,pCol)
  96. {
  97.    reg.ah = 2, reg.bh = 0, reg.dh = pRow, reg.dl = pCol;
  98.    interrupt(0x10,reg);
  99. }
  100.  
  101. GetCursor(pRow,pCol)
  102. {
  103.    reg.ah=3, reg.bh=0;
  104.    interrupt(0x10,reg);
  105.    pRow=reg.dh, pCol=reg.dl;
  106. }
  107.  
  108. SetCursorType(pStartingLine,pEndingLine)
  109. {
  110.    lCursor = ( 1 == va_arg() ) ? pStartingLine : (pStartingLine<<8) | pEndingLine ;
  111.    reg.ah=1, reg.cx=lCursor;
  112.    interrupt(0x10,reg);
  113. }
  114.  
  115. GetCursorType()
  116. {
  117.    reg.ah=3, reg.bh=0;
  118.    interrupt(0x10,reg);
  119.    return reg.cx;
  120. }
  121.  
  122. SetAttribute(pForeColor,pBackColor)
  123. {
  124.    if ( 1 == va_arg() )
  125.       slForeColor = pForeColor & 0xF, slBackColor = (pForeColor & 0xF0) >> 4;
  126.    else
  127.       slForeColor = pForeColor, slBackColor = pBackColor;
  128. }
  129.  
  130. ReadCharacter(pRow,pCol,pAttr)
  131. {
  132.    if ( 1 < va_arg() ) SetCursor(pRow,pCol);
  133.    reg.ah=8, reg.bh=0;
  134.    interrupt(0x10,reg);
  135.    if ( 1 == va_arg() ) pRow = reg.ah;
  136.    else if ( 3 == va_arg() ) pAttr = reg.ah;
  137.    return byte(reg.al);
  138. }
  139.  
  140. ScrWrite(pStrOrChar,pRow,pCol,pForeColor,pBackColor)
  141. {
  142.    if ( 3 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  143.    if ( !DataDimension(pStrOrChar) ) {
  144.       // write a single character
  145.       if ( 1 < va_arg() ) ScreenCursor(pCol,pRow);
  146.       reg.ah=9, reg.cx=1, reg.al=pStrOrChar;
  147.    } else {
  148.       // write a string
  149.       if ( 1 < va_arg() ) reg.dh=pRow, reg.dl=pCol;
  150.       else GetCursorPosition(reg.dh,reg.dl);
  151.       reg.ax=0x1301, reg.cx=strlen(pStrOrChar);
  152.       reg.es=segment(pStrOrChar), reg.bp=offset(pStrOrChar);
  153.    }
  154.    reg.bx=slForeColor|(slBackColor<<4);
  155.    interrupt(0x10,reg);
  156. }
  157.  
  158. Clear(pForeColor,pBackColor)
  159. {
  160.    if ( 2 == va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  161.    lSize = ScreenSize();
  162.    Scroll(0,0,0,lSize.row-1,lSize.col-1);
  163. }
  164.  
  165. Scroll(pLineCount,pTopRow,pLeftCol,pBottomRow,pRightCol,pForeColor,pBackColor)
  166. {
  167.    if ( pLineCount < 0 ) reg.ah=6, reg.al=-pLineCount;
  168.    else reg.ah=7, reg.al=pLineCount;
  169.    if ( 3 < va_arg() ) reg.ch=pTopRow, reg.cl=pLeftCol, reg.dh=pBottomRow, reg.dl=pRightCol;
  170.    else reg.ch=reg.cl=0, reg.dh=ScreenSize().row-1, reg.dl=ScreenSize().col-1;
  171.    if ( 3 == va_arg() ) slForeColor = pTopRow, slBackColor = pLeftCol;
  172.    else if ( 5 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  173.    reg.bh=slForeColor|(slBackColor<<4);
  174.    interrupt(0x10,reg);
  175. }
  176.  
  177.  
  178. TextBox(pTopRow,pLeftCol,pBottomRow,pRightCol,pForeColor,pBackColor,pTreatment)
  179. {
  180.    lSaveCursor = GetCursorType();
  181.    SetCursorType(HIDE_CURSOR);
  182.    if ( 5 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  183.    lTreatment = ( 1 & va_arg() ) ? lTreatment = va_arg(va_arg()-1) : 0 ;
  184.    // If supposed to fill the entire box then do whole box now
  185.    if !(lTreatment & NOFILL)
  186.       Scroll(0,pTopRow,pLeftCol,pBottomRow,pRightCol);
  187.    if ( lTreatment & Shadow ) {
  188.       lSaveFore = slForeColor, lSaveBack = slBackColor;
  189.       Scroll(0,pTopRow+1,pRightCol+1,pBottomRow+1,pRightCol+2,LIGHTGRAY,BLACK);
  190.       Scroll(0,pBottomRow+1,pLeftCol+2,pBottomRow+1,pRightCol,LIGHTGRAY,BLACK);
  191.       slForeColor = lSaveFore, slBackColor = lSaveBack;
  192.    }
  193.    // if need lines, then draw lines now
  194.    if ( lLineType = (lTreatment & (DOUBLE_LINE|SINGLE_LINE|0xFF)) ) {
  195.       if ( lLineType & 0xFF )
  196.          memset(lCorners,lLineType,4);
  197.       else
  198.          lCorners = SINGLE_LINE==lLineType ? '┌┐└┘' : '╔╗╚╝' ;
  199.       ScrWrite(lCorners[0],pTopRow,pLeftCol);
  200.       HorzLine(pTopRow,pLeftCol+1,lLen=pRightCol-pLeftCol-1,lLineType);
  201.       ScrWrite(lCorners[1]);
  202.       ScrWrite(lCorners[2],pBottomRow,pLeftCol);
  203.       HorzLine(pBottomRow,pLeftCol+1,lLen,lLineType);
  204.       ScrWrite(lCorners[3]);
  205.       VertLine(pTopRow+1,pLeftCol,lLen=pBottomRow-pTopRow-1,lLineType);
  206.       VertLine(pTopRow+1,pRightCol,lLen,lLineType);
  207.    }
  208.    SetCursorType(lSaveCursor);
  209. }
  210.  
  211. HorzLine(pRow,pLeftCol,pLen,pForeColor,pBackColor,pTreatment)
  212. {
  213.    if ( 4 < va_arg() ) slForeColor = pForeColor, slBackColor = pBackColor;
  214.    lTreatment = va_arg(va_arg()-1);
  215.    if ( lTreatment & 0xFF )
  216.       // fill line with plain text character
  217.       memset(lBuf,lTreatment,pLen);
  218.    else
  219.       // special line-drawing character for single or double line
  220.       memset(lBuf,SINGLE_LINE==lTreatment ? '─' : '═',pLen);
  221.    ScrWrite(lBuf,pRow,pLeftCol);
  222. }
  223.  
  224. VertLine(pTopRow,pCol,pLen,pForeColor,pBackColor,pTreatment)
  225. {
  226.    if ( 4 < va_arg()